package disanzhou;

import java.lang.reflect.Array;
import java.util.ArrayList;

abstract class Shape {
	public abstract double getArea();

		public static double sumAllArea(Shape[] shapes) {
		double sumAllArea=0;

		for (Shape shape : shapes) {
			sumAllArea+=shape.getArea();
		}
		
		return sumAllArea;
		}

	public static void main(String[] args) {
		ArrayList<Shape> arr =new ArrayList<Shape>();
		Shape[] S= new Shape[4];
	    arr.add(new Rectangle(1,2));
	    arr.add(new Rectangle(3,6));
	    arr.add(new Circle(2));
	    arr.add(new Circle(4));
	    System.out.println(Shape.sumAllArea((Shape[])arr.toArray(S)));
		// TODO Auto-generated method stub

	}

}
class Circle extends Shape{
	private int radius;
	
	public Circle(int radius) {
		this.radius=radius;
	}
			
	public double getArea() {		 
		return radius*radius*Math.PI;
	}
}
class Rectangle extends Shape{
	private int width;
	private int length;
	
	public Rectangle(int width,int length) {
		this.width=width;
		this.length=length;
	}

	public double getArea() {
		return width*length;
	}

	@Override
	public String toString() {
		return "Rectangle [width=" + width + ", length=" + length + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + length;
		result = prime * result + width;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Rectangle other = (Rectangle) obj;
		if (length != other.length)
			return false;
		if (width != other.width)
			return false;
		return true;
	}	



	
}
